package com.huaiwei.usmManager.modules.usm.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.huaiwei.usmManager.common.utils.NumberUtils;
import com.huaiwei.usmManager.common.utils.PageUtils;
import com.huaiwei.usmManager.common.utils.Query;
import com.huaiwei.usmManager.modules.usm.dao.GoodsSpecDao;
import com.huaiwei.usmManager.modules.usm.entity.GoodsEntity;
import com.huaiwei.usmManager.modules.usm.entity.GoodsSpecEntity;
import com.huaiwei.usmManager.modules.usm.service.GoodsService;
import com.huaiwei.usmManager.modules.usm.service.GoodsSpecService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class GoodsSpecServiceImpl extends ServiceImpl<GoodsSpecDao, GoodsSpecEntity> implements GoodsSpecService {
   @Autowired
   private GoodsService goodsService;

    @Override
    public PageUtils getPage(Map<String, Object> params) {
        String name=(String) params.get("goodspack");
        IPage<GoodsSpecEntity> page=this.page(new Query<GoodsSpecEntity>().getPage(params),new QueryWrapper<GoodsSpecEntity>()
                .like(StringUtils.isNotEmpty(name),"goods_pack",name));
        return new PageUtils(page);
    }

    @Override
    public PageUtils getGoodsBySpecId(Integer specId,Map<String,Object> params) {
        IPage<GoodsEntity> page=goodsService.page(new Query<GoodsEntity>().getPage(params),new QueryWrapper<GoodsEntity>()
        .eq("prospec_id",specId));
        return new PageUtils(page);
    }

    @Override
    public Boolean getCountBySpecId(Integer specId) {
        List<GoodsEntity> list=goodsService.list( new QueryWrapper<GoodsEntity>()
        .eq("prospec_id",specId)) ;
        if(list.size()==0){/*如果list无数据，证明可以删*/
            return true;
        }else{
            return false;
        }
    }
}
